<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ZJCA CMT 国密证书管理系统</title>
  </head>
  <body>
    <div id="root"></div>

    <script>
      (function () {
        var guardFlag = '__ZJCAAllJsErrorPatched';
        if (window[guardFlag]) return;

        var targetMessage = "Cannot read properties of undefined (reading '0')";
        var shouldIgnore = function (message, source) {
          if (!message || message.indexOf(targetMessage) === -1) return false;
          if (!source) return true;
          return source.indexOf('all.js') !== -1;
        };

        var swallow = function (event) {
          if (!event || !shouldIgnore(event.message, event.filename)) return false;
          event.preventDefault();
          event.stopImmediatePropagation();
          return true;
        };

        window.addEventListener(
          'error',
          function (event) {
            swallow(event);
          },
          true,
        );

        var previousOnError = window.onerror;
        window.onerror = function (message, source, lineno, colno, error) {
          var normalizedMessage =
            typeof message === 'string'
              ? message
              : (message && message.message) || (error && error.message) || '';
          var normalizedSource =
            typeof source === 'string'
              ? source
              : (message && message.filename) || (error && error.fileName) || '';

          if (shouldIgnore(normalizedMessage, normalizedSource)) {
            return true;
          }

          if (typeof previousOnError === 'function') {
            var result = previousOnError(message, source, lineno, colno, error);
            return result === true;
          }

          return false;
        };

        window[guardFlag] = true;
      })();
    </script>
    
    <!-- 引入ZJCA CMT API的JavaScript文件（仅WebSocket方式） -->
    <!-- jQuery - WebSocket通信必需 -->
    <script src="/zjca_cmt/jquery.min.js"></script>
    <script>
      // 如果本地jQuery加载失败，则从CDN加载
      window.jQuery || document.write('<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"><\/script>');
    </script>
    
    <!-- ZJCA CMT SDK核心文件（WebSocket方式） -->
    <!-- 注意：引入顺序必须与官方DEMO一致，主文件zjcacmt.js必须第一个加载 -->
    <script src="/zjca_cmt/zjcacmt.js"></script>
    <script src="/zjca_cmt/zjcacmt_cert.js"></script>
    <script src="/zjca_cmt/zjcacmt_key.js"></script>
    <script src="/zjca_cmt/zjcacmt_com.js"></script>
    <script src="/zjca_cmt/zjcacmt_websocket.js"></script>
    <script src="/zjca_cmt/zjcacmt_def.js"></script>
    <script src="/zjca_cmt/zjcacmt_err.js"></script>
    
    <!-- React应用入口 -->
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>
